﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data;
namespace DAL
{
    public class KQDAL
    {
        DBHelper db = new DBHelper();
        public List<KQModel> GetListAll()
        {
            string sql = $"select * from [dbo].[Kaoqin]";
            List<KQModel> list = new List<KQModel>();
            DataTable dt = db.GetData(sql).Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                KQModel DM = new KQModel();
                DM.TheID = Convert.ToInt32(dt.Rows[i]["TheID"].ToString());
                DM.TheDay = Convert.ToDateTime(dt.Rows[i]["TheDay"].ToString());
                DM.TheRoom = dt.Rows[i]["TheRoom"].ToString();
                DM.TheClass = dt.Rows[i]["TheClass"].ToString();
                DM.TheHumans = Convert.ToInt32(dt.Rows[i]["TheHumans"].ToString());
                DM.ThePeople = Convert.ToInt32(dt.Rows[i]["ThePeople"].ToString());
                DM.TheOut = Convert.ToInt32(dt.Rows[i]["TheOut"].ToString());
                DM.TheQuestion = dt.Rows[i]["TheQuestion"].ToString();
                DM.TheTeacher = dt.Rows[i]["TheTeacher"].ToString();

                list.Add(DM);
            }
            return list;
        }
        public bool ADD(KQModel DM)
        {
            string sql = $"insert into [dbo].[Kaoqin]values('{DM.TheDay}','{DM.TheRoom}','{DM.TheClass}','{DM.TheHumans}','{DM.ThePeople}','{DM.TheOut}','{DM.TheQuestion}','{DM.TheTeacher}')";
            if (db.SetData(sql))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
